using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;

public partial class Admin_CapNhatKhachHang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           
            LoadData();
        }
    }
   
    private void LoadData()
    {
        try
        {
            int id = int.Parse(Request.QueryString["id"]);

            tbKhachHangEntities khachHang = tbKhachHangBUS.GetByID(id);
            txt_MaKH.Text = khachHang.MaKH.ToString();
            txt_TenKH.Text = khachHang.HoTen.ToString();
            txt_Email.Text = khachHang.Email.ToString();           
            txt_DiaChi.Text = khachHang.DiaChi.ToString();
            txt_DienThoai.Text = khachHang.DienThoai.ToString();
            drgt.SelectedValue = khachHang.GioiTinh.ToString();           
        }
        catch
        {
            Response.Redirect("~/Admin/DanhSachKhachHang.aspx");
        }

    }

    protected void btn_Add_Click(object sender, EventArgs e)
    {
        try
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            tbKhachHangEntities khachHang = tbKhachHangBUS.GetByID(id);
            khachHang.HoTen = txt_TenKH.Text;
            khachHang.Email = txt_Email.Text;          
            khachHang.DiaChi = txt_DiaChi.Text;
            khachHang.DienThoai = txt_DienThoai.Text;
            khachHang.GioiTinh = drgt.SelectedValue;
            tbKhachHangBUS.Update(khachHang);
            Response.Redirect("~/Admin/DanhSachKhachHang.aspx");
        }
        catch
        {
            Response.Redirect("~/Admin/DanhSachKhachHang.aspx");
        }
        Response.Redirect(Request.RawUrl);
    }
}
